<%-- 
    Document   : search_news
    Created on : Oct 27, 2010, 2:19:49 PM
    Author     : M Bilal
--%>

<%@ page import="java.io.*,java.util.*,java.sql.*,java.net.*"%>
<%@ page import="wap.rockvilletech.portal.DBProc"%>
<%
    DBProc dbproc=DBProc.getInstance();
    String strSearchText=(request.getParameter("txtsrh")!=null && !request.getParameter("txtsrh").isEmpty())?request.getParameter("txtsrh").toString():"";
	boolean emptyCheck = request.getParameter("txtsrh").isEmpty();
    //Pagging
     int intBlockLength = 5, intRecordsToBeDisplayed = 0, intRecordsToBeFetched = 0, intCountTotal = 0, intPageID = 0, intLastPage = 0;
	String strPagingLinks = "", pid = "";
	boolean computePaging = false, isNext = true;
	pid = request.getParameter("pid") != null ? request.getParameter("pid").toString() : "0";
    Vector vNews = dbproc.getNewsSearch(pid, strSearchText);
    if(vNews!=null){
    intCountTotal=(Integer)vNews.get(0);
    intRecordsToBeDisplayed=intRecordsToBeFetched=(Integer)(vNews.get(1));
	try {
		intLastPage = intCountTotal / intRecordsToBeDisplayed;
		intPageID = Integer.parseInt(pid.toString());
		if (intPageID > intLastPage) {
	        intPageID = intLastPage;
	    }
		if(intCountTotal == (int)(intRecordsToBeDisplayed*(intPageID+1))) intLastPage--;
    } catch(NumberFormatException ex){
    }

    if (vNews.size()-1 < intRecordsToBeFetched) {
		intRecordsToBeDisplayed -= (intRecordsToBeFetched - vNews.size());
		intRecordsToBeFetched = vNews.size();
		isNext = false;
	}

    computePaging = intCountTotal >intRecordsToBeDisplayed;
   if(computePaging){
       // Call the method which will generate Page links

		wap.rockvilletech.util.Paging.computePaging(request, "search.jsp?",
				intRecordsToBeFetched, intRecordsToBeDisplayed,
				intCountTotal, intBlockLength, intLastPage, intPageID,
				isNext);
		strPagingLinks = wap.rockvilletech.util.Paging.getPagingLinks();
                }
    }//end vector if
%>
<div>
                <table cellpadding="0" cellspacing="0" width="100%">
           <tr><td align="left" style="padding:5px 0px 0px 10px;">
                        <table bgcolor="#d5d5d5" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td><img src="<%=request.getContextPath()%>/images/bar_left.png" alt="" /></td>
                                <%
                                	if(emptyCheck)
                                	{
                                		%>
                                		<td><b>&nbsp;Search Result&nbsp;</b></td>
                                		<%
                                	}
                                	else
                                	{
                                		%>
                                		<td><b>&nbsp;News Search&nbsp;</b></td>
                                		<%
                                	}
                                %>
                                
                                <td><img src="<%=request.getContextPath()%>/images/bar_right.png" alt="" /></td>
                            </tr>
                        </table>
               </td></tr>
           <tr><td align="left" style="background-image:url('images/new/catagory_top_part.jpg');background-repeat: repeat-x; padding:6px 0px 0px 0px; ">

<%
       try {
	       String ititle ="";
	       String strFeedUrl = "";
	       String strNewsId="";
	       if(emptyCheck)
	       {
	    	   strPagingLinks="Please enter your search keyword!";
	       }
	       else
		   {
		    	
		       String[] arrNews=null;
               if(vNews.size()==2){
                strPagingLinks="No Data Available!";
          		  }
          		 for (int idx = 2; idx < vNews.size(); idx++) {
            	   arrNews =(String[]) vNews.get(idx);
            	   strFeedUrl = arrNews[1];
            	   ititle = arrNews[2];
            	   	strNewsId=arrNews[0];
            	   	ititle = wap.rockvilletech.util.StringUtils.toUnicode(ititle);
            	   	try{
            	   	ititle=java.net.URLDecoder.decode(ititle,"UTF-8");
            	   	}catch(Exception exDecode){}
%>
		<div>&nbsp; - <a class="LinkIndex" href="<%=request.getContextPath()%>/news/content.jsp?feed=<%=strFeedUrl%>&txtsrh=<%=strSearchText%>&newsitemid=<%=strNewsId%>&ftitle=<%=strFeedUrl%>"><%=ititle%></a></div>
<%
          }}
		
		out.println(strPagingLinks);
               

       } catch (Exception exRssNewsSearch) {
       }
%>
    </td>
    </tr>
                </table>
           </div>
       <br/>

<%-- End --%>